<?php

namespace App\Api\Requests;

class UserRequest extends FormRequest
{

    public function rules()
    {
        switch($this->method()) {
            case 'POST':
                return [
                    'password' => 'required|string|min:6|confirmed',
                    'password_confirmation' => 'required|string',
                    'verification_key' => 'required|string',
                    'verification_code' => 'required|string',
                ];
                break;
            case 'PATCH':
                $userId = \Auth::guard('api')->id();
                return [
                    'username' => 'between:3,25|regex:/^[A-Za-z0-9\-\_]+$/|unique:users,username,' .$userId,
                ];
                break;
        }
    }

    public function messages()
    {
        return [
            'username.unique' => '用户名已被占用，请重新填写',
            'username.regex' => '用户名只支持英文、数字、横杆和下划线。',
            'username.between' => '用户名必须介于 3 - 25 个字符之间。',
            'username.required' => '用户名不能为空。',
            'password.required' => '密码不能为空',
            'password.min' => '密码不能小于6位',
            'password_confirmation.required' => '确认密码不能为空',
            'password.confirmed' => '确认密码和密码不一致',
        ];
    }
}